<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ taglib prefix="m" uri="/WEB-INF/mil.tld"%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<!-- Meta, title, CSS, favicons, etc. -->
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">
<title>起步 &middot; Bootstrap</title>
<!-- Bootstrap core CSS -->
<link href="/statics/bootstrap-3.0.0/css/bootstrap.css" rel="stylesheet">
<!-- Documentation extras -->
<link href="/statics/css/style.css" rel="stylesheet">
<link href="/statics/bootstrap-datetimepicker/css/bootstrap-datetimepicker.min.css" rel="stylesheet"/>
<!-- Favicons -->
<link rel="apple-touch-icon-precomposed" sizes="144x144"
	href="../docs-assets/ico/apple-touch-icon-144-precomposed.png">
<link rel="shortcut icon" href="../docs-assets/ico/favicon.png">
<!-- JavaScript -->
<script src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
</head>
<body>
	<!-- Header
    ================================================== -->
	<jsp:include page="include/header.jsp" />
	<!-- Content
    ================================================== -->
	<div class="container">
		<div class="row">
			<div class="col-md-3">
				<jsp:include page="include/menu.jsp" />
			</div>
			<div class="col-md-9" role="main">
				<h3 class="page-header" id="download">创建满就减</h3>
			</div>
		</div>
	</div>

	<!-- Footer
    ================================================== -->
	<jsp:include page="include/footer.jsp" />

	<!-- JavaScript
	================================================== -->
	<script src="/statics/bootstrap-3.0.0/js/bootstrap.js"></script>
	<script src="/statics/bootstrap-datetimepicker/js/bootstrap-datetimepicker.js"></script>
	<script src="/statics/js/application.js"></script>
	<script src="/statics/js/pagination.js"></script>
	<script type="text/javascript">
	var firstActive = true;
	
	$(function() {
		getProdList(1,10);
		$('#myTab li:last a span').html("("+$("input[name=content]").val().split(",").length+")");
		
		$('#myTab a').click(function (e) {
			e.preventDefault();
			$(this).tab('show');
			firstActive = $('#myTab li:first').hasClass("active");
			if(firstActive)
				getProdList(1,10);
			else
				getProdList(1,12);
		})
		
		$("tbody").on( "click",":checkbox[name=chk_list_max]",  function(){
			chooseProd(this.value);
		});
	})
	
	
	//查询商品列表
	function getProdList(pageNo, pageSize) {
		var href = "/prod/getProdList.do";
		$.getJSON(href, {"ids":firstActive?"":$("input[name=content]").val(),
			"pageNo":pageNo,
            "pageSize":pageSize}, function (data) {
			if(data.ret == 0){
				var _html;
				if(firstActive){
					$("table tbody tr").remove();
					$('#myTab li:first a span').html("("+data.data.totalRecord+")");
					for (index in data.data.list){
						elemObj = data.data.list[index];
						var checked = $("input[name=content]").val().indexOf(elemObj.id)>=0;
						_html = "<tr>"+
					 				"<td><input type=\"checkbox\" id=\"chk_list_max\" name=\"chk_list_max\" value=\""+elemObj.id+"\" "+(checked?"checked":"")+"/></td>"+
								 	"<td><img src=\""+elemObj.img+"\" width=\"50\" height=\"50\"/></td>"+
								 	"<td>"+elemObj.code+"<br><a href=\""+elemObj.url+"\" target=\"_blank\">"+elemObj.name+"</a></td>"+
								 	"<td>"+elemObj.price+"</td>"+
								 	"<td>"+elemObj.stock+"</td>"+
								 	"<td></td>"+
								"</tr>";
						$("table tbody").append(_html);
					}
					$("#pageProd").html(pageTag(data.data.pageNo,data.data.pageSize,data.data.totalRecord,getProdList));
				}
				else{
					$("#sale .row").html("");
					$('#myTab li:last a span').html("("+data.data.totalRecord+")");
					for (index in data.data.list){
						elemObj = data.data.list[index];
						_html = "<div class=\"col-sm-6 col-md-3\">"+
								 	//"<a href=\""+elemObj.url+"\" class=\"thumbnail\" target=\"_blank\"><img src=\""+elemObj.img+"\" alt=\"...\"></a>"+
								 	"<div class=\"thumbnail\">"+
								 		"<img src=\""+elemObj.img+"\">"+
								 		"<div class=\"caption\">"+
								 			"<h5>"+elemObj.name+"</h5>"+
								 			"<p>价格:11元  库存:22件</p>"+
								 		"</div>"+
								 	"</div>"+
								"</div>";
						$("#sale .row").append(_html);
					}
					$("#pageSale").html(pageTag(data.data.pageNo,data.data.pageSize,data.data.totalRecord,getProdList));
				}
			}
		});
	}
	
	
	//choose商品列表
	function chooseProd(id) {
		var content = $("input[name=content]").val();
		
		if(content.indexOf(id)==0)
			content = content.replace(id+",","");
		else if(content.indexOf(id)>0)
			content = content.replace(","+id,"");
		else 
			content += ","+id;
		
		$("input[name=content]").val(content);
		$('#myTab li:last a span').html("("+$("input[name=content]").val().split(",").length+")");
	}
	</script>
</body>
</html>